import json
from utils import get_db_connection, generate_new_table_name
from original_table_operations import OriginalTableOperations

def read_config(file_path):
    with open(file_path, 'r') as file:
        config = json.load(file)
    return config

class DatabaseManager:
    def __init__(self, config_file_path):
        self.config = read_config(config_file_path)
        self.original_table_ops = OriginalTableOperations(self.config)

    def replace_sensitive_data(self, table_name, sensitive_columns, mapping_table_name):  # 新增参数：映射表名称
        new_table_name = mapping_table_name  # 使用用户输入的映射表名称
        self.original_table_ops.create_sensitive_data_table(new_table_name, sensitive_columns)
        self.original_table_ops.insert_sensitive_data(table_name, sensitive_columns, new_table_name)
        self.original_table_ops.update_original_table(table_name, sensitive_columns, new_table_name)

    def close_connection(self):
        self.original_table_ops.close_connection()
